package com.example.mongocache.controller;

import com.example.mongocache.pojo.News;
import com.example.mongocache.service.NewsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class NewsController {

    @Autowired
    private NewsService newsService;

    @GetMapping("/news/{title}")
    public News getNews(@PathVariable String title){
        return newsService.getNewsByTitle(title);
    }


    @GetMapping("/updatenews")
    public String updatenews(String title,String content)
    {
        boolean bool=newsService.updateNewsContentByTitle(title,content);
        if(bool)
            return  "更新成功";
        else
            return  "更新失败";
    }

}
